<template>
  <div class="app-container">
    <basic-container v-show="showSearch">
      <common-search @handleQuery="handleQuery" @resetQuery="resetQuery">
        <el-form :model="queryParams" ref="queryForm" :inline="true" size="mini" label-width="100px">
          <el-form-item label="业务编号" prop="platSeqNo">
            <el-input v-model.trim="queryParams.platSeqNo" placeholder="请输入业务编号" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="单证编号" prop="billCode">
            <el-input v-model.trim="queryParams.billCode" placeholder="请输入单证编号" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="批次号" prop="manifestId">
            <el-input v-model.trim="queryParams.manifestId" placeholder="请输入批次号" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="关区代码" prop="customsCode">
            <el-input v-model.trim="queryParams.customsCode" placeholder="请输入关区代码" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="进出口" prop="iEFlag">
            <el-input v-model.trim="queryParams.iEFlag" placeholder="请输入进出口" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="业务类型" prop="businessType">
            <el-select v-model.trim="queryParams.businessType" placeholder="请选择业务类型" clearable>
              <el-option v-for="dict in dict.type.sys_bill_business_type" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="创建时间" prop="createTime">
            <el-date-picker clearable v-model.trim="queryParams.createTime" type="date"
              value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择创建时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="单证状态" prop="auditStatus">
            <el-select v-model.trim="queryParams.auditStatus" placeholder="请选择单证状态" clearable>
              <el-option v-for="dict in dict.type.data_sync_type" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
        </el-form>
      </common-search>
    </basic-container>

    <basic-container>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd('add')"
            v-hasPermi="['billsdecl:gEmptyBills:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleEdit('edit')"
            v-hasPermi="['billsdecl:gEmptyBills:edit']">编辑</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" icon="el-icon-upload2" :disabled="multiple" @click="handleDecl"
            v-hasPermi="['billsdecl:gEmptyBills:decl']">
            申报
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" icon="el-icon-refresh-right" :disabled="multiple"
            @click="handleDeclRepeat" v-hasPermi="['billsdecl:gEmptyBills:decl','billsdecl:gEmptyBills:chargeback']">
            重发(申报)
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" icon="el-icon-download" :disabled="multiple"
            @click="handleChargeback" v-hasPermi="['billsdecl:gEmptyBills:chargeback']">
            退单
          </el-button>
        </el-col>

        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
            v-hasPermi="['billsdecl:gEmptyBills:remove']">删除</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <!-- 列表 -->
      <basic-table ref="tableList" :columns="columns" :tableData="tableData" :total="pageParams.total"
        @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange" :loading="loading"
        :needCheckbox="true" @selectionChange="handleSelectionChange">
        <template #businessType="scope">
          <dict-value :list="dict.type.sys_bill_business_type" :dictCode="scope.row.businessType"></dict-value>
        </template>


        <template #auditStatus="scope">
          <dict-value :list="dict.type.bills_decl_status" :dictCode="scope.row.auditStatus"></dict-value>
        </template>

        <template #iEFlag="scope">
          <dict-value :list="dict.type.sys_i_e_flag" :dictCode="scope.row.iEFlag"></dict-value>
        </template>

        <template #operate="scope">
          <div class="option-menu">
            <el-button type="text" size="mini" class="table-edit" @click="handleDetail(scope.row)">
              详情
            </el-button>
          </div>
        </template>
      </basic-table>
    </basic-container>

    <!-- 新增、编辑 -->
    <add-edit ref="addEdit" :dialogType="dialogType" :rowData="rowData" :dict="dictProp" @handleQuery="handleQuery" />

    <!-- 详情 -->
    <detail-dialog ref="detail" :detailId="detailId" :dict="dictProp"></detail-dialog>

  </div>
</template>

<script>
  import {
    listGEmptyBills,
    delGEmptyBills,
    declGEmptyBills,
    declRepeatGEmptyBills,
    chargebackGEmptyBills
  } from "@/api/billsdecl/gEmptyBills";
  import addEdit from "./components/addEdit";
  import detailDialog from "./components/detailDialog";
  export default {
    name: "GEmptyBills",
    dicts: ['sys_bill_business_type', 'sys_i_e_flag', 'bills_goods_category', 'bills_decl_status'],
    components: {
      addEdit,
      detailDialog
    },
    data() {
      return {
        // 显示搜索条件
        showSearch: true,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          billCode: null,
          uniId: null,
          manifestId: null,
          transportName: null,
          fieldCode: null,
          fieldName: null,
          customsCode: null,
          customsName: null,
          startFieldCode: null,
          startFieldName: null,
          desFieldCode: null,
          desFieldName: null,
          declCopCode: null,
          declCopName: null,
          iEFlag: null,
          billType: null,
          businessType: null,
          declBy: null,
          declTime: null,
          declRetryNum: null,
          auditStatus: null,
          auditTime: null,
          auditRemark: null,
          chargebackReason: null,
          transferPlatSeqNo: null
        },
        // 遮罩层
        loading: true,
        // 列表数据
        tableData: [],
        columns: [
          {
            prop: "manifestId",
            label: "批次号",
            align: "center"
          },
          {
            prop: "transportName",
            label: "车牌号",
            align: "center"
          },
          {
            prop: "iEFlag",
            label: "进出口",
            align: "center",
             slot: true,
          },
          {
            prop: "businessType",
            label: "业务类型",
            align: "center",
            slot: true
          },
          {
            prop: "customsCode",
            label: "关区代码",
            align: "center"
          },
          {
            prop: "startFieldName",
            label: "过卡场所",
            align: "center"
          },
          {
            prop: "platSeqNo",
            label: "业务编号",
            align: "center"
          },
          {
            prop: "billCode",
            label: "单证编号",
            align: "center"
          },
          {
            prop: "declCopName",
            label: "报关企业",
            align: "center"
          },
          {
            prop: "createTime",
            label: "创建时间",
            align: "center"
          },
          {
            prop: "declTime",
            label: "申报时间",
            align: "center"
          },
          {
            prop: "auditStatus",
            label: "单证状态",
            align: "center",
            slot: true,
            fixed:"right"
          },
          {
            prop: "auditTime",
            label: "审核时间",
            align: "center"
          },
          {
            prop: "auditRemark",
            label: "审核意见",
            align: "center"
          },
          {
            prop: "operate",
            label: "操作",
            slot: true,
            width: 140,
            fixed: "right",
          },
        ],
        pageParams: {
          total: 0,
        },
        rowData: {},
        detailId: "",
        dialogType: "",
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        //详情显示的时候，表单编辑禁用
        isViewDisabled: false,

        // 空车作业单表格数据
        gEmptyBillsList: [],
      };
    },
    computed: {
      dictProp() { //字典list，为避免子组件重复调接口获取，用computed计算传值
        return {
           type: this.dict.type
        }
      }
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询空车作业单列表 */
      getList() {
        this.loading = true;
        listGEmptyBills(this.queryParams).then(response => {
          this.tableData = response.rows;
          this.pageParams.total = response.total;
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.$refs.tableList.pageParams.currentPage = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 分页
      handleSizeChange(val) {
        this.queryParams.pageSize = val.pageSize;
        this.getList();
      },
      handleCurrentChange(val) {
        this.queryParams.pageNum = val.currentPage;
        this.getList();
      },
      // 新增/编辑
      handleAdd(type) {
        this.dialogType = type;
        this.$refs.addEdit.open();
      },

      handleEdit(type) {
        this.dialogType = type;
        let plateSeqNo=this.ids[0];
        this.$nextTick(() => {
          this.$refs.addEdit.open(plateSeqNo);
          console.log(plateSeqNo);
        });
      },
      // 详情
      handleDetail(row) {
        this.detailId = row.platSeqNo;
        this.$nextTick(() => {
          this.$refs.detail.open(row);
        });
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.platSeqNo)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const platSeqNos = row.platSeqNo || this.ids;
        this.$modal.confirm('是否确认删除空车作业单编号为"' + platSeqNos + '"的数据项？').then(function() {
          return delGEmptyBills(platSeqNos);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      handleDecl(row) {
        const ids = row.platSeqNo || this.ids;
        this.$modal.confirm('是否确认申报业务编号为"' + ids + '"的数据项？').then(function() {
          return declGEmptyBills(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        }).catch(() => {});
      },
      handleDeclRepeat(row) {
        const ids = row.platSeqNo || this.ids;
        this.$modal.confirm('是否确认重试申报业务编号为"' + ids + '"的数据项？').then(function() {
          return declRepeatGEmptyBills(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        }).catch(() => {});
      },
      handleChargeback(row) {
        const ids = row.platSeqNo || this.ids;
        this.$modal.confirm('是否确认退单业务编号为"' + ids + '"的数据项？').then(function() {
          return chargebackGEmptyBills(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        }).catch(() => {});
      },
    }
  };
</script>



<style type="text/css">
  .el-form-item .el-select {
    width: 100%;
  }
</style>
